package com.vm.activity;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.android.volley.RequestQueue;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import com.vm.commons.CurrentUser;
import com.vm.commons.VMConst;
import com.vm.utils.MyVolley;
import com.wwtscapp.apk.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年3月19日 下午2:52:34]
 * @Version: [v1.0]
 * 
 */
public class FeedBackActivity extends Activity {
	protected static final String TAG = null;
	ImageView imgbtn_search_back;
	EditText et_QQ;
	EditText et_tel;
	EditText et_describe_content;
	Button btn_submit;
	private RequestQueue mQueue;
	String url;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feedback);
		mQueue = MyVolley.getRequestQueue();
		init();
	}

	public void init() {
		imgbtn_search_back = (ImageView) findViewById(R.id.imgbtn_search_back);
		imgbtn_search_back.setOnClickListener(btn_backListener);
		et_QQ = (EditText) findViewById(R.id.et_QQ);
		et_tel = (EditText) findViewById(R.id.et_tel);
		et_describe_content = (EditText) findViewById(R.id.et_describe_content);
		btn_submit = (Button) findViewById(R.id.btn_submit);
		btn_submit.setOnClickListener(feedBackListener);
	}

	OnClickListener feedBackListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			String qq = et_QQ.getText().toString();
			String phone = et_tel.getText().toString();
			String contain = et_describe_content.getText().toString();
			if (!contain.equals("")) {
				try {
					contain = URLEncoder.encode(contain, "UTF-8");
				} catch (UnsupportedEncodingException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				if (CurrentUser.USERID != null) {
					url = VMConst.REQUEST_URL + "addFeedBack?userId="
							+ CurrentUser.USERID + "&qq=" + qq + "&phone="
							+ phone + "&contain=" + contain;
				} else {
					url = VMConst.REQUEST_URL + "addFeedBack?" + "qq=" + qq
							+ "&phone=" + phone + "&contain=" + contain;
				}
				try {
					StringRequest stringRequest = new StringRequest(url,
							new Listener<String>() {

								@Override
								public void onResponse(String arg0) {
									// TODO Auto-generated method stub
									Toast toast = Toast.makeText(
											FeedBackActivity.this,
											"反馈提交成功,工作人员会尽快处理您的问题",
											Toast.LENGTH_SHORT);
									toast.show();
									et_QQ.setText("");
									et_tel.setText("");
									et_describe_content.setText("");
								}

							}, null);
					mQueue.add(stringRequest);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					Log.e(TAG, e.getMessage());
				}
			} else {
				Toast toast = Toast.makeText(FeedBackActivity.this, "请填写反馈内容",
						Toast.LENGTH_SHORT);
				toast.show();
			}
		}

	};

	OnClickListener btn_backListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// Log.i(TAG, "imgbtn_search_back返回按钮监听");
			onBackPressed();

		}
	};

	public void onBackPressed() {
		super.onBackPressed();
		System.out.println("按下了back键   onBackPressed()");
	}
}
